# -*- coding: utf-8 -*-  # 添加此行

'''
用户注册功能逻辑
'''

from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from database.database import get_db
from schemas.user import UserRegister
from crud.user import register_user

async def UserRegister(user: UserRegister, db: Session = Depends(get_db)):
    """
    用户注册接口
    
    参数:
    - user: 用户注册信息 (用户名、姓名、邮箱、密码)
    - db: 数据库会话
    
    返回:
    - 注册成功信息
    """
    try:
        result = register_user(db, user)
        return result
    except HTTPException as e:
        raise e
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"注册失败: {str(e)}")